package com.clouds.wms.cms;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.clouds.wms.bean.Cmsmk;
import com.clouds.wms.exception.SysException;
import com.clouds.wms.service.CmsmdService;
import com.clouds.wms.service.CmsmkService;
import com.clouds.wms.util.Function;
import com.clouds.wms.util.PagesBean;
import com.clouds.wms.util.RequestHelper;

@Controller
@RequestMapping("/cmsmk")
public class CmsmkController {

	private Log log = LogFactory.getLog(getClass());
	
	@Resource(name="cmsmkService")
	private CmsmkService cmsmkService;

	@Resource(name="cmsmdService")
	private CmsmdService cmsmdService;

	/**
	 * 日志查询
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws SysException
	 */
	@RequestMapping(value = "/cmsmkMain.xhtml")
	public String cmsmkMain(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException {
		model.addAttribute("allCmsmdList", cmsmdService.getAllCmsmdList());
		return "cms/cmsmk";
	}

	/**
	 * 列出所有的日志
	 * @param request
	 * @param response
	 * @return
	 * @throws SysException
	 */
	@RequestMapping(value = "/cmsmkList.xhtml")
	public String cmsmkList(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException {
		String start = RequestHelper.getString(request, "start");
		String end = RequestHelper.getString(request, "end");
		String mkad = RequestHelper.getString(request, "mdaa");
		int pageNumber = RequestHelper.getInt(request, "page", 1);// 要跳转的页号
		int pageSize = RequestHelper.getInt(request, "rows", 10);// 一页的条数
		PagesBean pb = cmsmkService.getCmsmkList(start, end, mkad, pageNumber, pageSize);
		List<Cmsmk> list = ((List<Cmsmk>)pb.getData());
		int count = pb.getCount();
		Map<String,Object> paraMap = new HashMap<String,Object>();
		paraMap.put("total", count);
		paraMap.put("rows", list);
		try {
			Function.toJson(response, paraMap);
		} catch (IOException e) {
			log.error(e.getMessage());
		}
		return null;
	}

}
